Features Scaling

i) Import Libraries

ii) Load Dataset

iii) Plot Dataset (observe x-y axis ranges)

iv) Z-Score Normalization

After z-score normalization, all features will have a mean of 0 and a standard deviation of 1.

To implement z-score normalization, adjust your input values as shown in this formula: $$x^{(i)}_j = \dfrac{x^{(i)}_j - \mu_j}{\sigma_j} \tag{4}$$ where $j$ selects a feature or a column in the $\mathbf{X}$ matrix. $µ_j$ is the mean of all the values for feature (j) and $\sigma_j$ is the standard deviation of feature (j). $$ \begin{align} \mu_j &= \frac{1}{m} \sum_{i=0}^{m-1} x^{(i)}_j \tag{5}\\ \sigma^2_j &= \frac{1}{m} \sum_{i=0}^{m-1} (x^{(i)}_j - \mu_j)^2 \tag{6} \end{align} $$

Implementation Note:

  • When normalizing the features, it is important to store the values used for normalization - the mean value and the standard deviation used for the computations.
  • After learning the parameters from the model, we often want to predict the prices of houses we have not seen before. Given a new x value (living room area and number of bed- rooms), we must first normalize x using the mean and standard deviation that we had previously computed from the training set.

Implementation

v) Plot Nomralized Features (observe x-y axis ranges)

vi) Plot & Compare Nomralized & Non-Normalized Features (observe x-y axis ranges)

Go To Home